//
//  SpecialDetailViewController.m
//  Coco_Music
//
//  Created by dlios on 15-7-1.
//  Copyright (c) 2015年 寇广超. All rights reserved.
//

#import "SpecialDetailViewController.h"

@interface SpecialDetailViewController ()

@end

@implementation SpecialDetailViewController
-(void)dealloc
{
    [_myArray release];
    [_myTableView release];
    [_myImageView1 release];
    [_myImageView2 release];
    
    
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor =[UIColor whiteColor];
    self.myArray =[NSMutableArray array];

    self.myTableView =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-64)];
    self.myTableView.backgroundColor =[UIColor whiteColor];
    self.myTableView.separatorStyle =UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.myTableView];
    self.myTableView.delegate= self;
    self.myTableView.dataSource =self;
    
    [self getData];
    
    
   
    
    self.myImageView1 =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height/3)];
    [self.view addSubview:self.myImageView1];
    
    
    UIVisualEffectView *visualEffct = [[UIVisualEffectView alloc]initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
    visualEffct.frame=self.myImageView1.frame;
    visualEffct.alpha =1;
    [self.myImageView1 addSubview:visualEffct];
    
    
    
    self.myImageView2 =[[UIImageView alloc]initWithFrame:CGRectMake(self.myImageView1.center.x-70, self.myImageView1.center.y-70 , 140, 140)];
    self.myImageView2.layer.masksToBounds =YES;
    self.myImageView2.layer.cornerRadius = 10;
    
    [visualEffct addSubview:self.myImageView2];
     self.myTableView.tableHeaderView = self.myImageView1;
    
    
    self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.HUD.labelText = @"正在加载,请稍后";
    [self.HUD show:YES];
    //自动刷新状态
    [self.myTableView.footer beginRefreshing];
    [self.myTableView.header beginRefreshing];
    
    //结束刷新
    [self.myTableView.footer endRefreshing];
    [self.myTableView.header endRefreshing];

    
    
}
#define SpecialDetailConnect @"http://api.dongting.com/song/album/%ld?"
#define SpecialDetailConnect1 @"app=ttpod&v=v7.9.4.2015052918&uid=&mid=iPad4%2C4&f=f320&s=s330&imsi=&hid=&splus=8.3&active=1&net=2&openudid=5df9002635a21cc5f7f660e71a16d1e35e5a04a0&idfa=B5F4461B-F9C7-4F1E-BA92-EB2E683311DF&utdid=VYEt7JjHCIUDAGowp1W3cSW3&alf=201200&bundle_id=com.ttpod.music"
-(void)getData
{
    NSString *url =[NSString stringWithFormat:SpecialDetailConnect,(long)self.SingerID];
    
    NSString *url1 =[NSString stringWithFormat:url,SpecialDetailConnect1];
    [AFN_block NSString:url1 Blokc:^(id request) {
        NSMutableDictionary *myDic = request;
      
        NSLog(@" hahsaha %@ %@",myDic,url1);
        
        NSMutableDictionary *dic1 =[myDic objectForKey:@"data"];
               for (NSString *str1 in dic1) {
                   SpecialDetail2 *special2 =[[SpecialDetail2 alloc]init];
                   
                   special2.name =[dic1 objectForKey:@"name"];
                   
                   special2.singerPicUrl =[dic1 objectForKey:@"singerPicUrl"];
            if ([str1 isEqualToString:@"songList"]) {
                
                for (NSMutableDictionary *songListDic in [dic1 objectForKey:@"songList"]) {
                    SpecialDetail *specialD =[[SpecialDetail alloc]init];
                   specialD.song_name = [songListDic objectForKey:@"name"];
                    specialD.singer_name =[songListDic objectForKey:@"singerName"];
                    specialD.album_name =[songListDic objectForKey:@"albumName"];
                    specialD.favorites =[[songListDic objectForKey:@"favorites"]integerValue];
                    specialD.audition_list =[songListDic objectForKey:@"auditionList"];
               
                    for (NSMutableDictionary *auditionDic in specialD.audition_list) {
                        specialD.duration =[auditionDic objectForKey:@"duration"];
                      
                    }
                   
                    
                    NSURL *url =[NSURL URLWithString:special2.singerPicUrl];
                    
                    [self.myImageView1 sd_setImageWithURL:url  placeholderImage:[UIImage imageNamed:@"cm2_default_artist_banner-1"]];
                     [self.myImageView2 sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"cm2_default_artist_banner-1"]];
                    
                    [self.myArray addObject:specialD];
                    
                }
                [self.myTableView reloadData];
                 [self.HUD hide:YES];
            }
               }
    }];
    
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.myArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier =@"cell";
    SpecialViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell ==nil) {
        cell =[[SpecialViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    
 
  cell.SpecoalD =[self.myArray objectAtIndex:indexPath.row];
     cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    cell.numberLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row+1];
    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.myTableView deselectRowAtIndexPath:indexPath animated:YES];
    
    PlayingViewController *playVC = [PlayingViewController shareHandleController];
    playVC.array = self.myArray;
    playVC.indexPath = indexPath.row;
    UINavigationController *naPlayVC = [[UINavigationController alloc]initWithRootViewController:playVC];
    [self presentViewController:naPlayVC animated:YES completion:^{
        
        
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
